package com.itheima.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

//TODO 添加注解
@Component
@Aspect
public class MonitorAdvice {

    private static int num = 1;

    //TODO 定义切入点
    @Pointcut("execution(void com.itheima.service.OrderService.placeOrder())")
    private void pt(){
    }

    //TODO 绑定切入点和通知的关系
  //  @Before("pt()")
    public void monitor(JoinPoint jp) {

        System.out.println("订单模块被调用：" + num++ + "次");
    }


    @Around("pt()")
    public void aroundtest(ProceedingJoinPoint pjp){
        System.out.println("通知前");
        try {
            pjp.proceed();
            System.out.println("通知后");
        } catch (Throwable throwable) {
            System.out.println("出错了");
            throwable.printStackTrace();
        }
    }

}
